import mockAS2.IMockAS2;

/**
 * Copyright (c) 2012 Gary Higham
 * Released under the MIT license
 * https://code.google.com/p/mock-as2/wiki/License
 *
 * Version: v0.1
 */
class mockAS2.Stub implements IMockAS2 {
	
	private var originalMethod : Function;
	private var objectWithMethodToStub : Object;
	private var methodToStub : String;
	
	public function Stub(object : Object, method : String, stubMethod : Function) {
		storeOriginalData(object, method);
		stub(object, methodToStub, stubMethod);
	}
	
	private function storeOriginalData(object : Object, method : String) : Void {
		objectWithMethodToStub = object;
		methodToStub = method; 
		originalMethod = object[methodToStub];
	}
	
	private function stub(object : Object, method : String, stubMethod : Function) : Void {
		object[method] = stubMethod;
	}

	public function restore() : Void {
		stub(objectWithMethodToStub, methodToStub, originalMethod);
	}
}
